import rxAjax from '@/assets/js/ajax.js';
import {Util} from '@lowcode/jpaas-common-lib';
import FormBoAttrDialog from "@/views/modules/form/bo/FormBoAttrDialog";

import {I18Parse,CommonLang} from '@lowcode/jpaas-common-lib';
import apiFormBoLang from '../../../locales/lang/impl/form/apiFormBoLang';
let lang = apiFormBoLang;
let i18n=function (langKey,text) {
    return I18Parse.getI18Val(lang.apiFormBo,langKey, text)
}

//业务实体属性 api接口
const FormBoAttrApi = {};

FormBoAttrApi.baseUrl= '/api-form/form/bo/formBoAttr';
FormBoAttrApi.FormEntityBaseUrl= '/api-form/form/bo/formBoEntity';
FormBoAttrApi.exportUrl= FormBoAttrApi.baseUrl + '/listExport';

//查询列表
FormBoAttrApi.query=function (parameter) {
  var url= FormBoAttrApi.baseUrl + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

/**
* 获取单记录
* @param pkId
* @returns {*}
*/
FormBoAttrApi.get =function(pkId) {
  var url= FormBoAttrApi.baseUrl + '/get?pkId=' + pkId;
  return rxAjax.get(url);
}

//保存数据
FormBoAttrApi.save =function(parameter) {
  var url= FormBoAttrApi.baseUrl + '/save';
  return rxAjax.postJson(url,parameter);
}

//删除数据
FormBoAttrApi.del =function(parameter) {
  var url= FormBoAttrApi.baseUrl + '/del';
  return rxAjax.postUrl(url,parameter);
}

/**
 * 根据表单ID获取属性。
 * @param formId
 * @returns {*}
 */
FormBoAttrApi.getByFormId =function(formId) {
  var url= FormBoAttrApi.baseUrl + '/getByFormId?formId=' + formId;
  return rxAjax.get(url);
}

/**
 * 根据实体ID获取属性。
 * @param formId
 * @returns {*}
 */
FormBoAttrApi.getByEntId =function(entId) {
  var url= FormBoAttrApi.baseUrl + '/getByEntId?entId=' + entId;
  return rxAjax.get(url);
}

/**
 * 根据实体ID获取属性。
 * @param formId
 * @returns {*}
 */
FormBoAttrApi.getByEntIds =function(entIds) {
    var url= FormBoAttrApi.baseUrl + '/getByEntIds?entIds=' + entIds;
    return rxAjax.postJson(url,entIds).then (res => {
        return res
    })
}

/**
 * 获取实体属性，如果是直接添加的实体，或通过表单生成的实体，带上标准字段。
 * @param entId
 * @returns {*}
 */
FormBoAttrApi.getIncludeStandAttrByEntId =function(entId) {
    var url= FormBoAttrApi.baseUrl + '/getIncludeStandAttrByEntId?entId=' + entId;
    return rxAjax.get(url);
}



//查询实体对应属性列表
FormBoAttrApi.queryToAttr=function (parameter) {
  var url= FormBoAttrApi.baseUrl + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

//查询实体列表
FormBoAttrApi.queryToBoEntity=function (boDefId) {
  var url= FormBoAttrApi.FormEntityBaseUrl + '/queryToBoEntity?boDefId='+boDefId;
  return rxAjax.get(url);
}

FormBoAttrApi.openBoAttrDialog=function(config,callback){
  var baseConf= {
    component:FormBoAttrDialog,
    title: i18n('formAttrs','获取表单属性')
  };
  let conf = { ...baseConf,...config };
  Util.open(conf,function(action,data){
    if(action!='ok'){
      return;
    }
    if(callback){
      callback(data);
    }
  });
};

export  default FormBoAttrApi;

